package com.ruoyi.web.controller.applet;

import com.ruoyi.applet.appletRegion.domain.AppletRegion;
import com.ruoyi.applet.appletRegion.service.IAppletRegionService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 小程序地区Controller
 * @author ruoyi
 * @date 2024-12-17
 */
@Controller
@RequestMapping("/applet/appletRegion")
public class AppletRegionController extends BaseController {
    
    private final String prefix = "applet/appletRegion";
    
    @Resource
    private IAppletRegionService appletRegionService;
    
    @RequiresPermissions("applet:appletRegion:view")
    @GetMapping()
    public String appletRegion() {
        return prefix + "/appletRegion";
    }
    
    /**
     * 查询小程序地区列表
     */
    @RequiresPermissions("applet:appletRegion:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(AppletRegion appletRegion) {
        startPage();
        List<AppletRegion> list = appletRegionService.selectAppletRegionList(appletRegion);
        return getDataTable(list);
    }
    
    /**
     * 导出小程序地区列表
     */
    @RequiresPermissions("applet:appletRegion:export")
    @Log(title = "小程序地区", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(AppletRegion appletRegion) {
        List<AppletRegion> list = appletRegionService.selectAppletRegionList(appletRegion);
        ExcelUtil<AppletRegion> util = new ExcelUtil<AppletRegion>(AppletRegion.class);
        return util.exportExcel(list, "小程序地区数据");
    }
    
    /**
     * 新增小程序地区
     */
    @GetMapping("/add")
    public String add() {
        return prefix + "/add";
    }
    
    /**
     * 新增保存小程序地区
     */
    @RequiresPermissions("applet:appletRegion:add")
    @Log(title = "小程序地区", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(AppletRegion appletRegion) {
        return toAjax(appletRegionService.insertAppletRegion(appletRegion));
    }
    
    /**
     * 修改小程序地区
     */
    @RequiresPermissions("applet:appletRegion:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap) {
        AppletRegion appletRegion = appletRegionService.selectAppletRegionById(id);
        mmap.put("appletRegion", appletRegion);
        return prefix + "/edit";
    }
    
    /**
     * 修改保存小程序地区
     */
    @RequiresPermissions("applet:appletRegion:edit")
    @Log(title = "小程序地区", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(AppletRegion appletRegion) {
        return toAjax(appletRegionService.updateAppletRegion(appletRegion));
    }
    
    /**
     * 删除小程序地区
     */
    @RequiresPermissions("applet:appletRegion:remove")
    @Log(title = "小程序地区", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(appletRegionService.deleteAppletRegionByIds(ids));
    }
}
